package com.fenghongzhang.module_main.model

import com.fenghongzhang.lib_core.utils.GSON
import com.google.gson.annotations.SerializedName
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody

object CommonMallConstant {
    /** 普通订单 */
    const val ORDER_TYPE_NORMAL = "normal"

    /** 龙豆订单 */
    const val ORDER_TYPE_DOU = "point"

    /** 整车 */
    const val MALL_GOODS_TYPE_VEHICLE = "vehicle"

    /** 配件 */
    const val MALL_GOODS_TYPE_PART = "part"

    /** 退款 */
    const val AFTER_SALES_TYPE_REFUND = "refund"

    /** 换货 */
    const val AFTER_SALES_TYPE_EXCHANGE = "exchange"

    /** 退货退款 */
    const val AFTER_SALES_TYPE_TURN_BACK = "turnBack"

    /** 分享商品 */
    const val C_SHARE_GOODS_DETAIL = "c_share_goods_detail"

    /** 分享积分商品 */
    const val C_SHARE_POINT_GOODS_DETAIL = "c_share_point_goods_detail"

    /** 活动商品详情 */
    const val C_SHARE_ACTIVITY_GOODS_DETAIL = "c_share_activity_goods_detail"

    /** 分享秒杀商品 */
    const val C_SHARE_SKILL_DETAIL = "c_share_skill_detail"

    /** 分享活动 */
    const val C_SHARE_ACTIVITY = "activity"
}

data class CommonShareBody(
    val id: Long? = null,
    val dataId: Long? = null,
    val hotDataId: Long? = null,
    // 分享类型、c_share_goods_detail:商品详情、c_share_skill_detail:秒杀商品详情,activity:活动详情
    val shareType: String = ""
) : BaseBody()

data class ApplyAfterSalesBody(
    var reason: String = "",//
    var type: String = "",// 申请售后类型(退款-refund， 换货-exchange，退货退款-turnBack)
    var orderCode: String = "",//
    var vouchers: List<Long> = ArrayList(),// 上传凭证
    var goodsList: List<ApplyAfterSalesGoodsParam> = ArrayList()
) : BaseBody()

data class ApplyAfterSalesGoodsParam(
    val resourceId: Long? = 0L,
    val orderDetailCode: String? = null
)

data class ExpressCodeCheckBody(
    val expressName: String,
    val expressCode: String,
    val expressNo: String,
    val orderType: String? = null,
    val orderCode: String? = null,
    val contact: String? = null
) : BaseBody()

object CouponBusinessTypes {
    const val NORMAL = "normal"
    const val SECKILL = "seckill"
    const val ACTIVITY = "activity"
}

// 选择商品sku计算优惠券最大优惠
data class CouponMaxDisBody(
    val payWay: String? = null,// 付款方式（full-全款支付，deposit-定金，配件-全额支付 整车根据选择情况）,默认全款支付,非必填
    val goodsSkuDto: List<GoodsSkuDtoParam>? = null,
    var couponCodes: List<String>? = null,
    var businessType: String = CouponBusinessTypes.NORMAL,// 业务类型(normal-普通商品,seckill-秒杀商品 activity-活动商品可传值），默认普通商品，非必填
) : BaseBody()

data class GoodsSkuDtoParam(
    val goodsSkuId: Long?,
    val dataId: Long? = null,// 非必填
    val number: Int
)

data class CommonPageBody(
    val id: Long = 0L,
    val areaId: Long = 0L,
    val mainId: Long = 0L,
    val dataId: Long? = 0L,
    val groupId: Long? = 0L,
    var queryType: String? = null,// 查询tab类型{normal-普通订单,point-龙豆订单}
    val keyWords: String? = null,// 订单号/商品编码/商品名称查询
    val status: String? = null,// 状态返回英文标识（unpaid-待支付 toBeDelivered-待发货 waitReceive-待收货 toBeEvaluated-待评价 finish-交易完成 close-交易关闭 success-交易成功 finish-已完成 toBeCart-待提车）
    var start: Int = 1,
    val limit: Int = 10,
    var sortKey: String? = null,
    var sort: String? = null
) {
    fun toJson(): String {
        val map = HashMap<String, Any>()
        map["start"] = start
        map["limit"] = limit
        if (id > 0)
            map["id"] = id
        if (dataId != null && dataId > 0)
            map["dataId"] = dataId
        if (groupId != null && groupId > 0)
            map["groupId"] = groupId
        if (mainId > 0)
            map["mainId"] = mainId
        if (areaId > 0)
            map["areaId"] = areaId
        if (!queryType.isNullOrEmpty())
            map["queryType"] = queryType!!
        if (!keyWords.isNullOrEmpty())
            map["keyWords"] = keyWords
        if (!status.isNullOrEmpty())
            map["status"] = status
        if (!sortKey.isNullOrEmpty())
            map["sortKey"] = sortKey!!
        if (!sort.isNullOrEmpty())
            map["sort"] = sort!!
        return GSON.toJson(map)
    }

    fun toRequestBody(): RequestBody {
        return RequestBody.create("application/json".toMediaType(), this.toJson())
    }
}

data class CategoryGoodsPageBody(
    val groupId: Long? = null,
    val start: Int = 1,
    val limit: Int = 10
) : BaseBody()

data class ModifyCartBody(
    val resourceId: Long = 0L,
    val goodsSkuCode: String? = null,
    val goodsSkuName: String? = null,
    val carCode: String? = null,
    val goodsSkuId: Long = 0L,
    val number: Int = 0,
) : BaseBody() {
    override fun toJson(): String {
        val map = HashMap<String, Any>()
        if (resourceId > 0)
            map["resourceId"] = resourceId
        if (goodsSkuId > 0)
            map["goodsSkuId"] = goodsSkuId
        if (number > 0)
            map["number"] = number
        if (!goodsSkuCode.isNullOrEmpty())
            map["goodsSkuCode"] = goodsSkuCode
        if (!goodsSkuName.isNullOrEmpty())
            map["goodsSkuName"] = goodsSkuName
        if (!carCode.isNullOrEmpty())
            map["carCode"] = carCode

        return GSON.toJson(map)
    }
}

data class GoodsInfoPriceDTO(
    val num: Int? = 0,
    val price: Double? = 0.0,
    val goodsId: Long? = 0L
)

data class BatchDelCollectionBody(
    val ids: List<String>? = null,
    val type: Int = 0
) : BaseBody()

data class MultiFollowBody(
    val memberIds: List<String>? = null
) : BaseBody()

data class InfoCommentValidationBody(
    val informationId: Long? = 0L,
    val parentId: Long? = 0L
) : BaseBody()

//data class SaveMyLocationBody(
//    val lat: Double = 0.0,
//    val lon: Double = 0.0,
//    @SerializedName("districtCode")
//    val areaCode: String? = "",
//    val cityCode: String? = "",
//    val provinceCode: String? = "",
//    val lastAddress: String? = ""
//) : BaseBody()

/** 通用的简单参数体，根据具体的值动态组成Body */
data class CommonSimpleBody(
    val id: Long? = 0,
    val addressId: Long? = 0,
    val dataId: Long? = 0,
    val skillId: Long? = 0,
    val goodsSkuId: Long? = 0,
    val resourceId: Long? = 0,
    val goodsId: Long? = 0,
    val groupId: Long? = 0,
    val mainId: Long? = 0,
    val amount: Double? = 0.0,
    val adType: String? = null,
    val orderCode: String? = null,
    val productType: String? = null,
    val afterOrderDetailCode: String? = null,
    val payOrderCode: String? = null,
    val payCode: String? = null,
    val payerTime: String? = null,
    val remark: String? = null,
    val payChannel: String? = null,// 支付渠道（aliPay-支付宝，wechat-微信）
    val source: String? = null,
    val keyword: String? = null,
    val code: String? = null,
    val expressCode: String? = null,
    val codes: List<String>? = null,
    val carDetailICodes: List<String>? = null,
    val goodsInfoList: List<GoodsInfoPriceDTO>? = null,
    val latitude: String? = null,
    val longitude: String? = null,
) {
    fun toJson(): String {
        val map = HashMap<String, Any>()
        // ID
        if (id != null && id > 0)
            map["id"] = id
        if (addressId != null && addressId > 0)
            map["addressId"] = addressId
        if (dataId != null && dataId > 0)
            map["dataId"] = dataId
        if (skillId != null && skillId > 0)
            map["skillId"] = skillId
        if (groupId != null && groupId > 0)
            map["groupId"] = groupId
        if (goodsSkuId != null && goodsSkuId > 0)
            map["goodsSkuId"] = goodsSkuId
        // 资源图片ID
        if (resourceId != null && resourceId > 0)
            map["resourceId"] = resourceId
        // 商品ID
        if (goodsId != null && goodsId > 0)
            map["goodsId"] = goodsId
        if (amount != null && amount > 0)
            map["amount"] = amount
        // 主ID
        if (mainId != null && mainId > 0)
            map["mainId"] = mainId
        // Banner类型
        if (!adType.isNullOrEmpty())
            map["adType"] = adType
        // 订单编号
        if (!orderCode.isNullOrEmpty())
            map["orderCode"] = orderCode
        if (!productType.isNullOrEmpty())
            map["productType"] = productType
        if (!afterOrderDetailCode.isNullOrEmpty())
            map["afterOrderDetailCode"] = afterOrderDetailCode
        // 支付号
        if (!payCode.isNullOrEmpty())
            map["payCode"] = payCode
        if (!payOrderCode.isNullOrEmpty())
            map["payOrderCode"] = payOrderCode
        if (!payerTime.isNullOrEmpty())
            map["payerTime"] = payerTime
        // 支付备注
        if (!remark.isNullOrEmpty())
            map["remark"] = remark
        // 支付渠道
        if (!payChannel.isNullOrEmpty())
            map["payChannel"] = payChannel
        // 订单状态
        if (!source.isNullOrEmpty())
            map["source"] = source
        // keyword
        if (!keyword.isNullOrEmpty())
            map["keyword"] = keyword
        if (!code.isNullOrEmpty())
            map["code"] = code
        if (!expressCode.isNullOrEmpty())
            map["expressCode"] = expressCode
        // 删除购物车
        if (!codes.isNullOrEmpty())
            map["codes"] = codes
        // 收藏购物车
        if (!carDetailICodes.isNullOrEmpty())
            map["carDetailICodes"] = carDetailICodes
        if (!goodsInfoList.isNullOrEmpty())
            map["goodsInfoList"] = goodsInfoList
        if (!latitude.isNullOrEmpty())
            map["latitude"] = latitude
        if (!longitude.isNullOrEmpty())
            map["longitude"] = longitude

        return GSON.toJson(map)
    }

    fun toRequestBody(): RequestBody {
        return RequestBody.create("application/json".toMediaType(), this.toJson())
    }
}

data class OrderPointCheckBody(
    val businessType: String = "point",
    var goodsSkuDto: List<GoodsSkuDtoParam>? = null
) : BaseBody()

/** 商城订单 */
data class CreateOrderBody(
    // 订单业务类型(normal-普通订单,point-积分订单)
    var orderType: String? = null,
    // 商品列表
    var goodsSkuDto: List<GoodsSkuDTO>? = null,
    // -----------------------------订单都有的
    // 加购好物
    var goodsAddSkuDto: List<GoodsSkuDTO>? = null,
    // 选择优惠券编码，支持多张
    var couponCodes: List<String> = ArrayList(),
    var payWay: String? = null,// 自提支付方式(deposit-定金,full-全款支付)
    var remark: String? = null,// 订单备注
    var takeWayDto: TakeWayDTO? = null,
    var takeVehicleWayDto: TakeVehicleWayDTO? = null,
    var storeInstallDto: StoreInstallDTO? = null,
    val source: String = "c_skl_app",
    val addressId: Long? = null,
    val payChannel: String? = null,
    val orderCode: String? = null
) : BaseBody()

/** 活动订单 */
data class CreateActivityOrderBody(
    var goodsSkuDto: GoodsSkuDTO? = null,
    // -----------------------------订单都有的
    // 加购好物
    var goodsAddSkuDto: List<GoodsSkuDTO>? = null,
    // 选择优惠券编码，支持多张
    var couponCodes: List<String> = ArrayList(),
    var payWay: String? = null,// 自提支付方式(deposit-定金,full-全款支付)
    var remark: String? = null,// 订单备注
    var takeWayDto: TakeWayDTO? = null,
    var takeVehicleWayDto: TakeVehicleWayDTO? = null,
    var storeInstallDto: StoreInstallDTO? = null,
    var payChannel: String? = null
) : BaseBody()

/** 秒杀订单 */
data class CreateSeckillOrderBody(
    var code: String? = null,// 秒杀排队号
    var goodsSkuDto: GoodsSkuDTO? = null,
    // -----------------------------订单都有的
    // 加购好物
    var goodsAddSkuDto: List<GoodsSkuDTO>? = null,
    // 选择优惠券编码，支持多张
    var couponCodes: List<String> = ArrayList(),
    var payWay: String? = null,// 自提支付方式(deposit-定金,full-全款支付)
    var remark: String? = null,// 订单备注
    var takeWayDto: TakeWayDTO? = null,
    var takeVehicleWayDto: TakeVehicleWayDTO? = null,
    var storeInstallDto: StoreInstallDTO? = null,
    var payChannel: String? = null
) : BaseBody()

data class TakeWayDTO(
    val takeWay: String? = null,// 配送方式;{delivery-物流配送,self-到店自提}，物流配送需要填写收货信息
    val receiversUserName: String? = null,// 收货人姓名
    val receiversMobile: String? = null,// 收货人电话
    val address: String? = null,// 收货地址
    val expressFeeStatus: String? = null,// 是否包邮（include-包邮，self-自付）
    val addressId: Long? = null,// 地址ID
    val expressFee: Double = 0.0// 邮费
)

/** 门店安装信息-非整车安装商品信息,选择门店安装填充信息 */
data class StoreInstallDTO(
    val storeId: Long?,
    val storeCode: String?,
    val storeName: String?,
    val goodsStoreSkuDto: List<GoodsStoreSkuDTO>?
)

data class GoodsStoreSkuDTO(
    val goodsId: Long?,
    val goodsSkuId: Long?,
    val resourceId: Long?,
    val goodsCode: String?,
    val goodsSkuCode: String?,
    val number: Int = 0,
    val remark: String? = null
)

data class DeliveryInfo(
    val deliveryCode: String? = null,
    val expressCode: String? = null
)

data class TakeVehicleWayDTO(
    val storeId: Long? = null,// 门店id
    val storeCode: String? = null,// 门店code
    val storeName: String? = null,// 门店名称
    val mobile: String? = null,// 联系电话
    val name: String? = null,// 提车人姓名
    val address: String? = null,// 详细地址
    val longitude: String? = null,// 经度
    val latitude: String? = null,// 纬度
) {
    fun hasStore(): Boolean {// 是否有门店信息
        return storeId != null || !storeCode.isNullOrEmpty() || !storeName.isNullOrEmpty()
    }

    fun hasData(): Boolean {// 是否有提车人信息
        return storeId != null || !storeCode.isNullOrEmpty() || !storeName.isNullOrEmpty() || !mobile.isNullOrEmpty() || !name.isNullOrEmpty()
    }
}

data class GoodsSkuDTO(
    // 秒杀ID
    val skillId: Long? = null,
    val hotDataId: Long? = null,
    val dataId: Long? = null,
    // 	商品id
    val goodsId: Long? = null,
    // 商品skuId
    val goodsSkuId: Long? = null,
    // 	商品sku图Id
    val resourceId: Long? = null,
    // 商品数量
    val number: Int = 0,
    val num: Int = 0,
    // 	商品编码
    val goodsCode: String? = null,
    // 	物料规格编码
    val goodsSkuCode: String? = null,
    // 	订单备注
    val remark: String? = null,
    // 购物车编码，如果是从购物车下单必传
    val carCode: String? = null,
) {

}

data class AddShoppingCarBody(
    val goodsId: Long? = 0,
    val goodsSkuId: Long? = 0,
    val goodsSkuCode: String? = "",
    val goodsSkuName: String? = "",
    val goodsCode: String? = "",
    val goodsName: String? = "",
    val resourceId: Long? = 0,
    val number: Int = 0
) : BaseBody()

data class MallGroupBody(
    val type: String = "c_home",// 展示位置{c_top赛科龙APP顶部导航,c_home赛科龙APP首页,c_detail赛科龙APP详情页}
    val isQueryGoods: Boolean = true,
    val size: Int = 4
) : BaseBody()

data class ActListPageBody(
    val index: Boolean = false,
    val start: Int = 1,
    val limit: Int = 10,
    // 最新-new 热门-hot
    val activityType: String? = ""
) : BaseBody()

object GoodsSortKeys {
    // 销量
    const val SOLD_NUM_SORT = "soldNumSort"

    // 新品
    const val NEW_GOODS_SORT = "newGoodsSort"

    // 价格
    const val PRICE_SORT = "priceSort"
}

data class GoodsSearchBody(
    var categorySeriesId: Long = 0,
    var categoryId: Long = 0,
    var id: Long = 0,
    var groupId: Long = 0,
    var brandId: Long = 0,
    var minMoney: Int = 0,
    var maxMoney: Int = 0,
    var start: Int = 1,
    var limit: Int = 10,
    var keyWord: String? = null,
    var tlineCode: String? = null,
    var sortKey: String? = null,// soldNumSort:销量,newGoodsSort：新品,priceSort：价格
    var sort: String? = null,
) {
    fun toJson(): String {
        val map = HashMap<String, Any>()
        map["start"] = start
        map["limit"] = limit
        if (categorySeriesId > 0)
            map["categorySeriesId"] = categorySeriesId
        if (id > 0)
            map["id"] = id
        if (categoryId > 0)
            map["categoryId"] = categoryId
        if (groupId > 0)
            map["groupId"] = groupId
        if (brandId > 0)
            map["brandId"] = brandId
        if (minMoney > 0)
            map["minMoney"] = minMoney
        if (maxMoney > 0)
            map["maxMoney"] = maxMoney
        if (!keyWord.isNullOrEmpty())
            map["keyWord"] = keyWord!!
        if (!tlineCode.isNullOrEmpty())
            map["tlineCode"] = tlineCode!!
        if (!sortKey.isNullOrEmpty())
            map["sortKey"] = sortKey!!
        if (!sort.isNullOrEmpty())
            map["sort"] = sort!!

        return GSON.toJson(map)
    }

    fun toRequestBody(): RequestBody {
        return RequestBody.create("application/json".toMediaType(), this.toJson())
    }
}

data class GoodsEvaluatingBody(
    var start: Int = 1,
    var limit: Int = 10,
    var goodsId: Long = 0,
    var bad: Boolean? = null,
    var good: Boolean? = null,
    var isImg: Boolean? = null,
) {
    fun toJson(): String {
        val map = HashMap<String, Any>()
        map["start"] = start
        map["limit"] = limit
        if (goodsId > 0)
            map["goodsId"] = goodsId
        if (bad != null)
            map["bad"] = bad!!
        if (good != null)
            map["good"] = good!!
        if (isImg != null)
            map["isImg"] = isImg!!

        return GSON.toJson(map)
    }

    fun toRequestBody(): RequestBody {
        return RequestBody.create("application/json".toMediaType(), this.toJson())
    }
}

//data class OrderEvaluationBody(
//    val orderCode: String? = null,
//    val goodsList: List<OrderEvaluationItem>? = null
//) : BaseBody()